package com.tqw.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tqw.order.vo.OrderListItemVO;
import com.tqw.pojo.Order;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: czm
 * @Date: 2022/04/16/15:58
 * @Description:
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    /*根据用户ID查询总的订单数*/
    @Select("select count(1) from goods_order where client_id = #{clientId} and goods_order.status !=3")
    Long getOrderTotal(Integer clientId);

    /*查询未付款/已付款/已取消 不同状态下的订单总数*/
    @Select("select count(1) from goods_order where client_id = #{clientId} and status = #{status}")
    Long getOtherOrderTotal(Integer clientId,Integer status);

    /*获取订单列表*/
    List<OrderListItemVO> getOrderList(@Param("start") int start, @Param("size") int size, @Param("clientId") int clientId);

    /*获取其他状态的订单列表*/
    List<OrderListItemVO> getOtherOrderList(@Param("start")int start, @Param("size")int size, @Param("clientId")int clientId,@Param("status")int status);

    /*根据订单号id查询订单信息*/
    @Select("select * from goods_order where order_id = #{orderId}")
    Order getOrderInfoByOrderId(String orderId);

    /*删除订单,假删除*/
    @Update("update goods_order set status = 3 where order_id = #{orderId}")
    void delete(String orderId);

    /*取消订单*/
    @Update("update goods_order set status = 2 where order_id = #{orderId}")
    void cancel(String orderId);

    void updatePayOrder(@Param("order") Order order);
}
